<template>
  <div>
    <!--1.视图-->
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="广告位名称">
        <el-input v-model="formInline.name" placeholder="广告位名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="list">查询</el-button>
        <el-button type="primary" @click="openAdd">添加</el-button>
      </el-form-item>
    </el-form>
    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column
          prop="name"
          label="广告位名称"
          width="180">
      </el-table-column>
      <el-table-column
          prop="spacekey"
          label="秘钥">
      </el-table-column>
      <el-table-column
          prop="createtime"
          label="创建时间">
      </el-table-column>
      <el-table-column
          prop="updatetime"
          label="更新时间">
      </el-table-column>
      <el-table-column
          prop="isdel"
          label="是否下线">
          <template slot-scope="s">
            <el-popover placement="top">
              <div slot="reference" class="name-wrapper">
                <el-tag size="medium">{{ s.row.isdel == "0" ? "未下线" : "已下线" }}</el-tag>
              </div>
            </el-popover>
          </template>
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">修改</el-button>
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @current-change="gopage"
        :page-size="size"
        layout="total, prev, pager, next"
        :total="total">
    </el-pagination>

    <el-dialog title="添加" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="广告位名称" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="秘钥" :label-width="formLabelWidth">
          <el-input v-model="form.spacekey" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="是否下线" :label-width="formLabelWidth">
          <el-radio-group v-model="form.isdel">
            <el-radio label="0">未下线</el-radio>
            <el-radio label="1">已下线</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="修改" :visible.sync="dialogFormVisible1">
      <el-form :model="form1">
        <el-form-item label="广告位名称" :label-width="formLabelWidth">
          <el-input v-model="form1.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="秘钥" :label-width="formLabelWidth">
          <el-input v-model="form1.spacekey" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="是否下线" :label-width="formLabelWidth">
          <el-radio-group v-model="form1.isdel">
            <el-radio label="0">未下线</el-radio>
            <el-radio label="1">已下线</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "PromotionSpaceView",
  data() {
    return {
      //2.属性定义
      tableData:[],
      formInline:{},
      size:3,
      current:1,
      total:0,
      form:{},
      form1:{},
      dialogFormVisible:false,
      dialogFormVisible1:false,
    }
  }, methods: {
    //3.自定义函数
    list(){
      this.axios.post("/promotion/list?current="+this.current+"&size="+this.size,this.formInline).then(res=>{
        this.tableData = res.data.data.list
        this.total = res.data.data.total
      })
    },
    gopage(current){
      this.current = current;
      this.list();
    },
    openAdd(){
      this.dialogFormVisible = true;
    },
    add(){
      this.axios.post("/promotion/add",this.form).then(res=>{
        if (res.data.code==200){
          this.$message.success(res.data.msg)
          this.dialogFormVisible = false;
          this.list();
        }else{
          this.$message.error(res.data.msg)
        }
      })
    },
    handleClick(row){
      this.form1=row;
      this.dialogFormVisible1=true;
    }
  }, created() {
    //4.钩子函数
    this.list();
  }
}
</script>

<style scoped>

</style>
